<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>     
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style.css" rel="stylesheet" type="text/css" />
<link href="./css/dtree.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/dtree-permit.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var roleName = document.getElementById("roleName");
		var roleDesc = document.getElementById("roleDesc");
		
		var functionIds = document.getElementsByName("cFunction");
		
		if(roleName.value == ""){
			alert("<fmt:message key='role.lable.roleName'/><fmt:message key='common.message.empty'/>");
			return false;
		}
		if(roleDesc.value == ""){
			alert("<fmt:message key='role.lable.roleDesc'/><fmt:message key='common.message.empty'/>");
			return false;
		}
		
		var sign = 0;
		for(var i = 0; i < functionIds.length; i++){
			if(functionIds[i].checked)sign = sign + 1;
		}
		
		if(sign <= 0){
			alert("<fmt:message key='role.message.function'/>");
			return false;
		}
		return true;
	}

	function back(){
		window.location.href = "./role.do";
		window.location.target = "main";
	}
	
	function save(){
		if(checkForm()){
			document.addRoleForm.action = "./role.do?action=addRole";
			document.addRoleForm.target = "main";
			document.addRoleForm.submit();
		}
	}
	
	function initPage(result,repeat){
		if(result == 1){
			alert("<fmt:message key='common.message.addSuccess'/>");
		}
		if(repeat == 1){
			alert("<fmt:message key='common.message.addFail'/><fmt:message key='role.lable.roleName'/><fmt:message key='common.message.exist'/>");
		}
	}
	
-->
</script>
</head>
<body onload="initPage('${result}','${repeat}')">
<form name="addRoleForm" action="" method="post">
	<table class="table_frame" cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<table class="table_title" cellpadding="0" cellspacing="0">
					<tr>
						<td class="title_lab" colspan="3">
							&nbsp;&nbsp;&nbsp;&nbsp;<fmt:message key='role.title.add'/>
						</td>
					</tr>
					<tr><td height="15"></td></tr>
					<tr>
						<td valign="bottom">&nbsp;
							<a href="javascript:save();" title="<fmt:message key='common.button.save'/>" hidefocus="true"><fmt:message key='common.button.save'/></a>
						</td>
						<td valign="bottom" align="right">
							<a href="javascript:back();" title="<fmt:message key='common.button.back'/>" hidefocus="true"><fmt:message key='common.button.back'/></a>&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="5"></td>
		</tr>
		<tr>
			<td>
				<table class="table1">
					<tr>
						<td valign="top" width="">
							<table class="table_input" cellpadding="0" cellspacing="0" style="margin: 0 0 0 100px;">
								<tr>
									<td class="" width="15%"><fmt:message key='role.lable.roleCode'/><fmt:message key='common.sign'/></td>
									<td class="">${roleCode}<input id="roleCode" name="roleCode" type="hidden" value="${roleCode}"/></td>
								</tr>
								<tr>
									<td class="" width="15%"><fmt:message key='role.lable.roleName'/><fmt:message key='common.sign'/></td>
									<td class="" width="">
										<input id="roleName" name="roleName" class="input_long" type="text" value="${role.roleName}"/>
									</td>
								</tr>
								<tr>
									<td class="title3" width="15%"><fmt:message key='role.lable.roleDesc'/><fmt:message key='common.sign'/></td>
									<td class="title3" width="">
										<input id="roleDesc" name="roleDesc" class="input_long" type="text" value="${role.roleDesc}"/>
									</td>
								</tr>
								<!-- 
								<tr>
									<td class="" width="15%">角色英文名称：</td>
									<td class="" width="">
										<input id="roleNameEn" name="roleNameEn" class="input_long" type="text" value="${role.roleNameEn}"/>
									</td>
								</tr>
								<tr>
									<td class="title3" width="15%">角色英文描述：</td>
									<td class="title3" width="">
										<input id="roleDescEn" name="roleDescEn" class="input_long" type="text" value="${role.roleDescEn}"/>
									</td>
								</tr>
								 -->
							</table>
						</td>
					</tr>
					<tr>
						<td valign="top" style="border-top: solid 1px #94b8e9;"><font style="height: 30px;"></font>
							<table class="table_input" cellpadding="0" cellspacing="0" style="margin: 0 0 0 100px;">
								<tr>
									<td class="title3">
										<script type="text/javascript">
										<!--				
											d = new dTree('d');
											d.add('0','-1','<font color=#4269B4><b><fmt:message key='role.title.functionTree'/></b></font>');
										//-->
										</script>
										
										<c:forEach var="function" items="${functions}">
										<c:if test="${function.id != 1 && function.id != 6 && function.id != 11 && function.id != 14}">
										<script type="text/javascript">
										<!--				
											d.add(${function.id},${function.parentId},'cFunction','${function.id}',
												'<c:choose><c:when test='${language==2}'>${function.functionNameEn}</c:when><c:otherwise>${function.functionName}</c:otherwise></c:choose>'
												,'','','','','','','','');
										//-->
										</script>
										
											<c:forEach var="operate" items="${operates}">
											<c:if test="${operate.functionId == function.id}">
											<script type="text/javascript">
											<!--				
												d.add(${operate.id}+1000,${operate.functionId},'cOperate','${operate.functionId}#${operate.id}',
													'<c:choose><c:when test='${language==2}'>${operate.operateNameEn}</c:when><c:otherwise>${operate.operateName}</c:otherwise></c:choose>'
													,'','','','','','','','');
											//-->
											</script>
											</c:if>
											</c:forEach>
										</c:if>	
										</c:forEach>
										
										<script type="text/javascript">
										<!--				
											document.write(d);
										//-->
										</script>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>